package com.lz.football.module.guide.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.greensock.TweenLite;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.lz.football.module.court.CourtView;
	import com.lz.football.module.guide.Guide;
	import com.lz.football.module.leagueMatch.view.PreMatchPanel;
	import com.lz.football.module.main.view.MainView;
	
	import common.lvAward.ILvAwardView;
	import common.lvAward.LvAwardView;
	import common.match.MatchPanel;
	
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import lz.controls.CompGlobalDef;
	import lz.controls.managers.AnimationManager;
	import lz.controls.managers.PopUpManager;

	/**
	 *第一场比赛引导 
	 * @author lake
	 * 
	 */	
	public class FirstMatchGuideView extends Guide
	{
		public function FirstMatchGuideView()
		{
			super();
		}
		/**
		 *初始化 
		 * 第一核心：比赛！
			官方说法：比赛是实力最直观的体现，从预选赛一路打到欧冠吧！
			1L：小伙伴桑，向着夕阳奔跑吧！
			2L：Goal！Goal！Goal！
			3L：first blood！
		 */		
		override protected function initView():void
		{
			super.initView();
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_1");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtnClickHandler);
			//disable
			MainView.playerSearchBtn.mouseEnabled = false;
			MainView.clubBtn.mouseEnabled = false;
		}
		/**
		 * 对话框按钮点击
		 * (获得比赛馆图标）
		 * @param e
		 * 
		 */		
		override protected function dialogBtnClickHandler(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtnClickHandler);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			sceneBtn = Reflection.createInstance("com.football.main.stadiumBtn");
			var appearMc :MovieClip = Reflection.createInstance("com.football.guide.AppearAtSkin");
			DisplayObjectUtil.removeAllChildren(appearMc.mc.mc);
			appearMc.mc.mc.addChild(sceneBtn);
			sceneBtn.x = -16;
			sceneBtn.y = -14;
			(sceneBtn as InteractiveObject).mouseEnabled = false;
			addDispToStage(appearMc);
			var gpoint :Point = MainView.stadiumBtn.localToGlobal(new Point(0,0));
			AnimationManager.moveToThing(new Point(appearMc.x,appearMc.y),appearMc,gpoint,{delay:1,overwrite:0},.5);
			TweenLite.delayedCall(1.5,showStadiumFuncIcon);
		}
		/**
		 *显示球场功能按钮
		 */		
		private function showStadiumFuncIcon():void
		{
			MainView.stadiumBtn.visible = true;
			removeBgMark();
			//限制区域
			var rectPoint :Point = MainView.stadiumBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,MainView.stadiumBtn.width,MainView.stadiumBtn.height);
			step();
			//指向球场
			var arrrowPoint :Point = new Point(curClickRect.x + curClickRect.width/2,curClickRect.y - 5);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,0);
			sceneBtn = MainView.stadiumBtn;
			arrowAngle = 0;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete);
		}
		/**
		 *加载完毕 
		 * @param e
		 * 
		 */		
		private function onLoadResComplete(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete);
			//限制区域
			var rectPoint :Point = CourtView.leagueBtn.view.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,CourtView.leagueBtn.view.width,CourtView.leagueBtn.view.height);
			step();
			//指向联赛
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn = CourtView.leagueBtn.view;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete1);
		}
		/**
		 *加载完毕 
		 * @param e
		 * 
		 */		
		private function onLoadResComplete1(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete1);
			removeArrowMc();
			initDialog();
			//enable
			MainView.playerSearchBtn.mouseEnabled = true;
			MainView.clubBtn.mouseEnabled = true;
		}
		/**
		 *场景内对话框 
		 * 预选赛
			官方说法：基础联赛，是通向甲级联赛的必经之路！
			1L：什么基础联赛！就是屌丝中的屌中屌，弱鸡中的战斗机！
			2L：信不信我第一场比赛会输掉？
			3L：库里挖。。。
		 */		
		private function initDialog():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_2");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn2_1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn2_1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(.2,showArrowToChallBtn);
		}
		/**
		 *指向挑战按钮 
		 */		
		private function showArrowToChallBtn():void
		{
			removeBgMark();
			//限制区域
			var rectPoint :Point = PreMatchPanel.challengeBtn.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y,PreMatchPanel.challengeBtn.width,PreMatchPanel.challengeBtn.height);
			step();
			//指向挑战按钮
			var arrrowPoint :Point = new Point(curClickRect.x,curClickRect.y + curClickRect.height/2);
			addArrowToScenePure(arrrowPoint.x,arrrowPoint.y,-90);
			sceneBtn = PreMatchPanel.challengeBtn;
			arrowAngle = -90;
			//事件
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete2);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
		}
		/**
		 *开始加载比赛资源 
		 */		
		private var panelUI :MatchPanel;//比赛框
		private function onLoadResStart2_0(e:NotifierEvent):void
		{
			//提交引导
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.POST_GUIDE,{step:1}));
			
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
			removeArrowMc();
			GlobalDef.AlertContainer.addChild(bgMark);
			panelUI = e.params as MatchPanel;
			panelUI.removeEvtListener();
		}
		/**
		 *球队介绍完毕 
		 * @param e
		 * 
		 */		
		private function onLoadResComplete2(e :Event):void
		{
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete2);
			TweenLite.delayedCall(3,initDialog_1);
			GlobalDef.GameWindowContainer.addChild(bgMark);
			//限制区域
			var rectPoint :Point = panelUI.localToGlobal(new Point(0,0));
			curClickRect = new Rectangle(rectPoint.x,rectPoint.y + 80,panelUI.width,panelUI.height - 80);
			step();
		}
		/**
		 * 场景内对话框 
		 *	进攻方向
			官方：比赛中玩家的球队全部向上进攻！
			1L：就是自家球门在下边呗~
			2L：就是对手球门在上边呗~
			3L：一个字，上 
		 * 
		 */		
		private function initDialog_1():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_3");
			GlobalDef.GameWindowContainer.addChild(bgMark);
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn1_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn1_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn1_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			TweenLite.delayedCall(10,initDialog_2);
		}
		/**
		 * 场景内对话框 
		 *	射门
				官方说法：自己选择射门的按钮！
				1L：高手用着都说好！
				2L：低手用着也很屌！
				3L：美术！
		 * 
		 */		
		private function initDialog_2():void
		{
			_symbolSkin = Reflection.createInstance("com.lz.guide.res.GuidePanel_4");
			addDispToStage(_symbolSkin);
			_symbolSkin.alpha = 0;
			TweenLite.to(_symbolSkin,.3,{alpha:1,delay:.2});
			dialogBtn = _symbolSkin.closeBtn;
			dialogBtn.addEventListener(MouseEvent.CLICK,dialogBtn2_Click);
		}
		/**
		 *对话框点击 
		 * @param e
		 * 
		 */		
		private function dialogBtn2_Click(e :MouseEvent):void
		{
			dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			AnimationManager.facadeOut(_symbolSkin,{},.2);
			GlobalDef.GameContainer.addChild(bgMark);
			var lvAwardView :ILvAwardView = Reflection.createInstance("common.lvAward.LvAwardView");
			lvAwardView.initUI();
			lvAwardView.showView(0);
			PopUpManager.addPopUp(lvAwardView as DisplayObject,GlobalDef.AlertContainer,GlobalDef.StageWidth,GlobalDef.StageHeight,true);
		}
		/**
		 * 
		 * 返回
		 */		
		private function onRemoveModuleHandler(e :Event):void
		{
			
		}
		/**
		 *执行 
		 * 
		 */		
		override public function process():void
		{
			initView();
		}
		/**
		 *清理 
		 * 
		 */		
		override public function clear():void
		{
			if(dialogBtn)
			{
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtnClickHandler);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_1_Click);
				dialogBtn.removeEventListener(MouseEvent.CLICK,dialogBtn2_Click);
			}
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_intro",onLoadResComplete2);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE+"_start",onLoadResStart2_0);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete1);
			AppEventDispatcher.getInstance().removeEventListener(NotifierEvent.MODULE_LOAD_RES_COMPLETE,onLoadResComplete);
			super.clear();
			TweenLite.killTweensOf(initDialog_1);
			TweenLite.killTweensOf(initDialog_2);
			panelUI = null;
		}
		///////////////华丽分割线///////////////////
		/**
		 *重置UI 
		 */		
		override public function resetUI():void
		{
			
		}
	}
}